home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2007 April
/
CHIP CD (4 - 2007).iso
/
beeld
/
3d
/
ArtOfIllusion24-Mac.dmg
/
Art of Illusion
/
ArtOfIllusion.jar
/
bsh
/
commands
/
dirname.bsh
< prev
next >
Wrap
Text File
|
2005-05-23
|
837b
|
32 lines
/**
Return directory portion of path based on the system default file separator.
Note: you should probably use pathToFile() to localize the path relative
to BeanShell's working directory and then file.getAbsolutePath() to get
back to a system localized string.
<p>
Example: to change to the directory that contains the script we're
currently executing:
<pre>
// Change to the directory containing this script
path=pathToFile( getSourceFileInfo() ).getAbsolutePath();
cd( dirname( path ) );
</pre>
*/
bsh.help.cd = "usage: dirname( path )";
String dirname( String pathname )
{
String dirName = ".";
// Normalize '/' to local file separator before work.
int i = pathname.replace('/', File.separatorChar ).lastIndexOf(
File.separator );
if ( i != -1 )
dirName = pathname.substring(0, i);
return dirName;
}